package com.cloudptt.wp.ui.address.map;

import java.util.ArrayList;
import java.util.List;

import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Marker;
import org.osmdroid.views.overlay.Overlay;
import org.osmdroid.views.overlay.OverlayManager;
import org.osmdroid.views.overlay.infowindow.InfoWindow;

import android.content.Context;
import android.graphics.drawable.Drawable;

public class PointMarkerUtil {

	public static final int TYPE_USERLOC = 0;
	public static final int TYPE_MEASUER = 1;
	private Context mContext;
	private MapView mMapView;
	private OverlayManager mOverlayManager;
	private List<Overlay> mUserLocMarkerList = new ArrayList<Overlay>();
	private List<Overlay> mMeasureMarkerList = new ArrayList<Overlay>();

	public PointMarkerUtil(Context context, MapView mapView) {
		// TODO Auto-generated constructor stub
		mContext = context;
		mMapView = mapView;
		mOverlayManager = mMapView.getOverlayManager();
	}

	public Marker addMarkerToMap(GeoPoint p, int markDrawableId, InfoWindow infoWindow, int type){
		Marker pointMarker = new Marker(mMapView);
		pointMarker.setPosition(p);
		Drawable drawable = mContext.getResources().getDrawable(markDrawableId);

		pointMarker.setIcon(drawable);
		pointMarker.setDraggable(false);
		pointMarker.setInfoWindow(infoWindow);


		if(mMapView != null){
			if(!mOverlayManager.contains(pointMarker)){
				mMapView.getOverlayManager().add(pointMarker);
				switch (type) {
				case TYPE_USERLOC:
					mUserLocMarkerList.add(pointMarker);
					break;
				case TYPE_MEASUER:
					mMeasureMarkerList.add(pointMarker);
					break;

				default:
					break;
				}

			}
		}

		return pointMarker;
	}

}
